home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / mus / edit / AGMSRecordSound4.lha / AGMSRecordSound.doc < prev    next >
Text File  |  1993-06-16  |  18KB  |  391 lines

  1.                          AGMSRecordSound
  2.  
  3. AGMSRecordSound is a Modula-2 program by Alexander G. M. Smith which
  4. records sound samples to disk, using a standard parallel port audio
  5. digitizer.  AGMSRecordSoundPS3 is a modified version that works with
  6. version 3.0+ PerfectSound hardware.
  7.  
  8. To get you started, try this command:
  9.  
  10.   AGMSRecordSound ram:test verbose
  11.  
  12. Type a control-C to stop it.  You can play the resulting file with
  13. AGMSPlaySound or some other sound player.
  14.  
  15.  
  16. Propoganda
  17.  
  18. Since AGMSRecordSound doesn't need to fit the whole sample into one
  19. contiguous memory block, you can record samples longer than your memory
  20. size (up to 2 gigabytes).  It also multi-tasks so you can see the screen
  21. and do other things while recording, unlike all other sound digitizer
  22. programs I know of.
  23.  
  24.  
  25. Anti-propoganda
  26.  
  27. The downside of this is crummy audio quality.  Other digitizers take
  28. over the computer while recording since that is the best way to get
  29. better quality.  The trouble comes from code that temporarily disables
  30. interrupts, making AGMSRecordSound's interrupt routine miss a sound
  31. sample.  This happens all time time - whenever memory is allocated or
  32. deallocated, interrupts are disabled to prevent other programs from
  33. interfering.  Hopefully Commodore will put in some DMA circuits for
  34. digitizing so that we can get good quality and multitasking.
  35.  
  36.  
  37. Requirements
  38.  
  39. AGMSRecordSound requires sound sampler hardware plugged into the
  40. parallel port.  I've tested it with AMAS (records from the right
  41. channel) and it should work with most other parallel port digitizers
  42. (try left if right doesn't work).  If you have SunRize Industries'
  43. PerfectSound 3 digitizer then you have to use a different version of
  44. this program: AGMSPlaySoundPS3.  You also need to have the arp.library
  45. file (version 39 or 1.3) in your LIBS: directory.  Other than that, it
  46. should work on all Amigas.
  47.  
  48.  
  49. How It Works
  50.  
  51. An interrupt routine is set up for audio channel 1 (right side) that
  52. samples the parallel port, copies the data to the audio register and
  53. copies it to a buffer in memory.  Every time audio channel 1 needs a new
  54. sound sample, this interrupt routine is called.  When a buffer becomes
  55. full, it moves to the next buffer and signals the main program.  If
  56. there are no empty buffers to be filled, the interrupt routine will slow
  57. down the audio channel to a lower sampling rate (around 440 Hz) so that
  58. the processor will have more CPU time for running tasks (less used by
  59. the interrupt code).  You can still hear the sounds but they won't be
  60. stored in the buffer (not recorded in other words) and they will sound
  61. strange (like a dog growling under water) due to the lower sampling
  62. rate.  When an empty buffer becomes available, it will resume filling at
  63. normal speed.
  64.  
  65. The other half of AGMSRecordSound is a process that dumps filled buffers
  66. to a disk file.  If it is faster at emptying buffers than the interrupt
  67. routine is at filling them, it will go to sleep and wait for a signal:
  68. control-C (a signal from the user to stop recording) and control-F (a
  69. signal from the interrupt routine that another buffer is full).  In the
  70. PerfectSound version, it also responds to control-E (steps up the volume
  71. control).  After dumping each buffer, it can optionally test for a
  72. couple of stop conditions: reaching the maximum number of bytes or the
  73. sound being quiet for a long enough time. 
  74.  
  75.  
  76. Sound Quality
  77.  
  78. The problems with disabled interrupts cause pops and similar noises -
  79. great if you are trying to simulate an old scratchy record (or to record
  80. one), but otherwise annoying.  The trick for getting "good" sound
  81. quality is to set the sampling rate to minimize this problem.
  82.  
  83. A really low sampling rate means that the disabled interrupt won't last
  84. long enough to cause trouble.  After interrupts are re-enabled, the
  85. pending audio interrupt will get through and the sample will only be
  86. delayed in time for a short while.  Samples after the delayed one will
  87. be back on schedule.  Unfortunately, most people don't like to record at
  88. 1kHz :-).  However, if you have a faster computer (I only have an A2000)
  89. then the disabled times will be shorter and sound quality should go up.
  90.  
  91. A really high sampling rate will suck up so much CPU time that only the
  92. interrupt routine will be running; every time it finishes sampling,
  93. another interrupt comes in.  This is actually quite useful (more later).
  94. You can tell that this is happening by the lack of mouse pointer
  95. movement when you move the mouse.  However, as soon as all the buffers
  96. are full, the interrupt routine will go into idle mode.  This frees up
  97. CPU cycles for running other tasks - like the mouse pointer movement and
  98. buffer saving.  As soon as one buffer has been saved, the interrupt
  99. routine will pick up speed and things will be frozen.
  100.  
  101. At high sampling rates, no other task is running and disabling
  102. interrupts.  This means high quality sound, almost as good as those
  103. dedicated non-multitasking sampler programs.  The catch is that nothing
  104. is recorded while the buffer is being dumped to disk.  So, if you can
  105. put up with brief pauses then you can use this mode.
  106.  
  107. Also, you can use AGMSRecordSound as an ordinary sound digitizer.  Just
  108. set the buffer size to fill up your whole memory (many smaller buffers
  109. are preferable since the interrupt routine can fill all but the one
  110. buffer being emptied - try buffers 20 size 100000 if you want to fill up
  111. 2 meg of memory).  Then set the sampling rate to one that uses all the
  112. CPU time for sampling (12kHz is good on my A2000, you will need larger
  113. rates on faster computers).
  114.  
  115. At ridiculously high sampling rates, the interrupt routine will be
  116. running flat out at a speed less than the one you requested.  This will
  117. result in a sample that is higher pitched than reality when you play it
  118. back.
  119.  
  120.  
  121. Embedded IFF Information
  122.  
  123. The output file is an IFF file.  You have lots of command line options
  124. available for specifying optional information (like sample name, author
  125. etc).  Unfortunately some other sound sample processing programs can't
  126. handle the extra info (but AGMSPlaySound can!).  If you find that you
  127. want to type in more information than will fit on a command line, put
  128. the long command line into a script file and execute it.
  129.  
  130.  
  131. Help
  132.  
  133. Most of the arguments to the program are obvious if you know audio
  134. terminology and computer terminology.  Anyways, you really don't have to
  135. specify any arguments except the name of the file to be created.  For
  136. on-line help, just type a ? as the argument to get the standard ARP /
  137. AmigaDOS command template.  A second ? typed at the template prompt will
  138. print the program credits.  The Verbose option also explains in more
  139. detail what the current settings are.  They are intuitively obvious
  140. (well, to me :-), but just in case you aren't intuitive about audio
  141. stuff, I'll describe the parameters in detail near the end of this
  142. message.
  143.  
  144.  
  145. Stolen Channels
  146.  
  147. This program won't let other programs steal its sound channel (channel 1
  148. to be specific).  It allocates it with maximum priority and thus hangs
  149. on to it.  If you are using AGMSPlaySound at the same time as you are
  150. recording, AGMSPlaySound will be bumped off channel 1 and will reappear
  151. on whatever other channel is free.  If someone else has channel 1 with
  152. the highest priority then AGMSRecordSound won't try recording.
  153.  
  154.  
  155. Error Handling
  156.  
  157. The main source of errors is from the file system.  In particular, you
  158. may encounter a disk full error once in a while :-).  When an error
  159. occurs, AGMSRecordSound stops whatever it is doing and shuts down.  It
  160. will return a return code of 10 when something goes wrong.
  161.  
  162. Now, more about those disk full errors.  I've set things up so that the
  163. file you are recording to is closed as if you had normally ended
  164. recording.  Since it is an IFF file, this means going back and filling
  165. in the size of the sample in previously written data near the beginning
  166. of the file.  It seems to work when using the old file system (OFS) but
  167. doesn't work under the fast file system (FFS).  Well, I tried.
  168.  
  169.  
  170. Technical Notes
  171.  
  172. Well, I found out a bit while writing this program.  Ok, two bits, make
  173. that three or four after I figured out the PS3 hardware :-).  For one
  174. thing, I found out how to use a digitizer: set CIAA port B to be all
  175. inputs (the parallel port).  Set CIAB port A pins POUT and SEL to be
  176. outputs.  The sampler spews out bytes to the parallel port with no
  177. handshaking, at some rate that I assume is pretty fast.  Some digitizers
  178. use a high level on SEL to connect the right audio input to the sampler
  179. and a high level on POUT to connect the left channel.  AMAS just
  180. seems to use the POUT bit to select left or right and seems to use right
  181. instead of left.  Whatever.  Once you have the desired channel, you can
  182. get a sample byte by reading the parallel port byte.  Subtract $80 from
  183. it to make it into a signed number and store it away.  Allow a small
  184. amount of time between switching from left to right (or vice versa) to
  185. let the sampler update its value (the time for a few instructions should
  186. be enough).
  187.  
  188. The PerfectSound 3.0+ hardware is a different story.  The sample byte is
  189. split between the parallel port (CIAA port B) and the miscellaneous bits
  190. port (CIAB port A).  The low 6 bits of parallel data (PB5-PB0 in CIAA)
  191. are actually the high six bits of the sample (shift them left by two).
  192. The low two bits of the sample are in the printer POUT (paper out) and
  193. BUSY signals (PA1-PA0 in CIAB).  As before, SEL (PA2 in CIAB) controls
  194. the left / right (zero is left).  So, what do PB6 and PB7 in CIAA do? A
  195. lot! The PerfectSound digitizer has a latched output, PB6 triggers the
  196. latch.  Set PB6 to zero to latch a value, read the sample, and set PB6
  197. back to one to start digitizing the next sample (I assume that's what
  198. it's doing).  PB7 is the gain control.  Normally you run the hardware
  199. with PB7 set to one.  If you toggle PB7 to zero and back, the volume
  200. control will be stepped up or down one notch of 16 levels.  SEL controls
  201. the volume direction (as well as left/right), zero for decreasing the
  202. volume.  The volume gain control wraps around from minimum to maximum
  203. and as far as I could tell, there isn't any way of telling what the
  204. current gain setting is or of setting it to minimum or maximum.
  205.  
  206. I experimented a bit with ways of generating interrupts before I clued
  207. in that no interrupts happen while interrupts are disabled.  CIA timers
  208. running continously are good.  Audio channels themselves are also good
  209. for making a periodic interrupt (and at exactly the same speed as
  210. playback too).  I even tried using an audio channel to generate an
  211. interrupt slightly before the audio channel I was using for timing would
  212. signal the next time period.  The early interrupt routine would then
  213. busy wait for the timing channel interrupt.  The "slightly" grew to over
  214. 800 CPU clock cycles before I got slightly improved sound (hey - a way
  215. of determining how long those disabled times are), slightly improved at
  216. a very slow sampling rate that made it useless.
  217.  
  218.  
  219. Feedback
  220.  
  221. If you have any feature requests or find any bugs, please send me a
  222. message.  I'm on several of the Ottawa BBX's (a BBS written by SteveX)
  223. and my commercial info service names are listed in the program's second
  224. help message (agmsmith@BIX.com and 71330.3173@CompuServe.com).
  225.  
  226.  
  227. Distribution
  228.  
  229. AGMSRecordSound is FreeWare.  Copyright (c) 1993 by Alexander G. M. Smith.
  230. That means that you can use it freely, can't blame me for anything that goes
  231. wrong (there are probably a few bugs left), and you shouldn't expect more
  232. from it than you paid for it.  Also, don't blame me if your hard drive fills
  233. up and then has problems with invalid directory structures - it happens to
  234. me too.
  235.  
  236.  
  237. File/A
  238.  
  239. Names the file where the sample will be stored.  Any existing file by
  240. this name will be erased.  A required keyword.  You can specify NIL: if
  241. you just want to monitor your digitizer without recording the sound to a
  242. file.  Only works in versions of AmigaDOS that support NIL:. 
  243.  
  244.  
  245. Verbose/S
  246.  
  247. When this command switch is used, lots of interesting messages will be
  248. displayed.  All the parameter settings will be shown.  During recording
  249. you can see what buffers are being dumped.
  250.  
  251.  
  252. Buffers/K
  253.  
  254. This parameter specifies the number of buffers (any old ram is used) to
  255. use for recording the sound.  You need at least 2.  While the system is
  256. recording one buffer, the others can be emptied to disk.  Try the
  257. verbose command switch to watch the buffers being emptied and to see how
  258. changing the number of buffers affects performance.  Gee, I sure like
  259. these reuseable documentation paragraphs - I just changed "play" to
  260. "record" :-)
  261.  
  262.  
  263. BufferSize/K
  264.  
  265. This parameter sets the size of each sound buffer.  The default is
  266. 100000 bytes, the maximum is about 2000000000 bytes :-).  As mentioned
  267. elsewhere, AGMSRecordSound doesn't need to use any chip ram at all.
  268. Buffers use general purpose ram.  For best performance, use large
  269. buffers.  That is because DOS can write a large chunk of data faster
  270. than several small chunks (less overhead).
  271.  
  272.  
  273. Hz/K
  274.  
  275. This parameter controls the record rate.  It is in units of samples per
  276. second, or bytes per second since each sample is one byte long (compact
  277. disks have 2 byte samples and thus sound better).  The default is 7781
  278. hz, less for the PerfectSound version due to extra overhead in reading
  279. each sample.  The highest rate on my A2000 that lets you record and
  280. simultaneously save to disk (no gaps) is about 8500 hz.  A speed of
  281. 12000 hz is good for better quality sound with small gaps between
  282. buffers.  See the discussion on sound quality about picking values for
  283. hz.
  284.  
  285. The Hz setting is internally translated into a code value for the
  286. hardware.  Since the hardware doesn't have all that many code values,
  287. only a few frequencies are actually available.  A frequency near the one
  288. you specified will be picked.  Note that this is half the playback code
  289. value since playback plays words (pairs of bytes) while we only record a
  290. byte at a time.
  291.  
  292.  
  293. StopSize/K
  294.  
  295. This parameter specifies the maximum size of the sound sample file.  The
  296. default is two billion.  When this many bytes of data have been written,
  297. the sampling process will be stopped.  Because the interrupt routine may
  298. have filled up a few buffers before this much data has been written, you
  299. will get a bit more than the stop size in your file. 
  300.  
  301.  
  302. StopQuiet/S
  303.  
  304. This switch triggers a neat feature requested by Hans Kerkhof who wanted
  305. something to record people calling in to a TV show.  If you specify
  306. StopQuiet then the sampling will also stop when the input is quiet for a
  307. long enough period of time.  This could also be useful for those of you
  308. making telephone answering machines.  The next few command line
  309. arguments control the definition of "quiet" and how much quiet is
  310. needed. 
  311.  
  312.  
  313. QuietTime/K
  314.  
  315. This parameter lets you specify the integer number of seconds of quiet
  316. that will make the program stop recording.  The number is approximate
  317. and will be converted into a count of quiet sound sample buffers (see
  318. BufferSize) that would cover roughly the time you request.  The minimum
  319. time possible is the time it takes to record one sound sample buffer. 
  320. If you specify the Verbose option, you can see the quiet time shown as
  321. the number of quiet buffers and the amount of real time that corresponds
  322. to.  The default value is zero (that becomes the time it takes to record
  323. one buffer).  Note that QuietTime is spelt with two "t"s in the middle,
  324. I often misspell it and get the error "Bad positional argument."
  325.  
  326.  
  327. QuietVolume/K
  328.  
  329. If you have StopQuiet turned on, then each buffer will be examined after
  330. it has been dumped to determine if it is "quiet".  A number of samples
  331. (adding up to 32 per second) will be picked out from the buffer and
  332. averaged together (or rather, the absolute value of each picked out
  333. sample will be averaged).  The resulting value, from 0 to 127, is a
  334. statistical estimate volume level of that buffer.  If you turn on the
  335. verbose option, it will show the buffer volume estimates.  If the volume
  336. is less than or equal to the QuietVolume you specify then that buffer
  337. counts as being "quiet".  If you get a certain number (determined by
  338. QuietTime) of quiet buffers in a row, then the program will stop. 
  339.  
  340.  
  341. Name/K
  342.  
  343. This lets you specify the name of the song or whatever you have
  344. recorded.  If it is more than one word, put it in double quotes.
  345.  
  346.  
  347. Copyright/K
  348.  
  349. This is for the IFF copyright notice inside your sound sample.  Specify
  350. something like "1991, Alexander G. M. Smith".
  351.  
  352.  
  353. Author/K
  354.  
  355. The author of this sample.  If it is music then that is relatively
  356. obvious.  I don't know who is the author of the sound of a toilet
  357. flushing, maybe the toilet manufacturer? Don't specify it if you don't
  358. want an author.
  359.  
  360.  
  361. Anno=Annotation/...
  362.  
  363. An endless list of annotation.  You can use the short form of the
  364. keyword (Anno) or the long form (Annotation).  The values are strings
  365. (as many as you want) of annotation text.  It can be whatever you want,
  366. usually something that describes the sample: anno "This is my first hour
  367. long sound sample" "The sound of the dripping tap was created by using
  368. the kitchen sink." "Use at your own risk."
  369.  
  370.  
  371. Control-C Etc.
  372.  
  373. Control-C will abort the program as soon as possible.  This can take a
  374. while if it is busy dumping a buffer.
  375.  
  376. Control-E will step up the volume on the PerfectSound hardware, if you
  377. are using AGMSRecordSoundPS3 (does nothing otherwise).  Don't hit the
  378. key too fast, when AGMSRecordSoundPS3 is running the rest of the
  379. operating system is slowed down and can't process your signals fast
  380. enough.  In fact, it's so slow that you can overflow something (probably
  381. the supervisor stack) by typing a lot of Control-CDEF's, even in another
  382. program's window.  The result is a visit from the guru (crash #3
  383. usually).
  384.  
  385. Control-F is used by the interrupt routine to tell the main program that
  386. there is another full buffer.  You can use it to if you want to wake up
  387. a poor little sleepy program (doesn't do any harm, unless you type it
  388. too quickly :-).
  389.  
  390. - Alex
  391.